# 8系列策略为宣传视频策略
from enum import Enum
from core.object import Interval
from core.template import BacktestingTemplate
from core.constant import *
from model.model2.factor.factor_am import ArrayManagerFactor


class Symbol(Enum):
    # DDQ = Model.DefaultSymbol.value
    GZMT = "600519.SH"
    # ZSYH = "600036.SH"


class P(Enum):
    # 结构参数
    cash = 100000
    shortcash = False
    commission = 0.00001
    am_size = 30
    symbols = [mem.value for mem in Symbol]
    # intervals = [Interval.MINUTE, Interval.MINUTE5, Interval.MINUTE15]  # 策略需要的所有K线周期
    intervals = [Interval.MINUTE]  # 策略需要的所有K线周期
    interval = Interval.MINUTE  # 原始回测数据的K线周期
    # 策略参数
    wide_wave_period = 240


class DDQStrategy(BacktestingTemplate):
    def __init__(self, p_dc):
        super().__init__(p_dc)
        self.close_index = 0
        self.hold_time = 200

    def on_full(self):
        volume = self.size_dc[Symbol.GZMT.value]
        qty = self.qty_dc[Symbol.GZMT.value]
        if self.index % 10000 == 0:
            print(f"$$$$$$$$$$$$$$${self.index}$$$$$$$$$$$$$$$$")
        am_1: ArrayManagerFactor = self.am_container.get(Symbol.GZMT.value, Interval.MINUTE)
        close_val = am_1.close[-1]
        # 红三兵形态对未来n个K线走势的影响
        three_write_cond = am_1.n_write_soldiers(n=3)
        if volume == 0:
            if three_write_cond:
                self.sell(Symbol.GZMT.value, size=qty*0.98)
                self.close_index = self.index + self.hold_time
        elif volume < 0:
            if self.index >= self.close_index:
                self.buy(Symbol.GZMT.value, size=-volume)
                self.close_index = 0



